package com.example.administrator.zhongyichou.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import com.example.administrator.zhongyichou.Bean.BaseEventBean;
import com.example.administrator.zhongyichou.R;
import com.example.administrator.zhongyichou.adapter.PublicityDetailsAdapter;
import com.example.administrator.zhongyichou.base.BaseActivity;
import com.example.administrator.zhongyichou.help.DateUtils;
import com.example.administrator.zhongyichou.help.Preview;
import com.example.administrator.zhongyichou.help.StringImageToList;
import com.example.administrator.zhongyichou.net.NetConfig;
import com.example.administrator.zhongyichou.net.core.HttpLoader;
import com.example.administrator.zhongyichou.net.core.RequestHttpLoader;
import com.example.administrator.zhongyichou.net.protocol.PublicityDetailsProtocol;
import com.example.administrator.zhongyichou.view.HeaderView;
import com.example.administrator.zhongyichou.view.MyGridView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lichenyu on 2017/11/24.
 * 描述：
 */

public class PublicityDetailsActivity extends BaseActivity<PublicityDetailsProtocol> {
    @BindView(R.id.headerview)
    HeaderView headerview;
    @BindView(R.id.gridview)
    MyGridView gridview;
    @BindView(R.id.gridview1)
    MyGridView gridview1;
    @BindView(R.id.txt_name)
    TextView txtName;
    @BindView(R.id.txt_age)
    TextView txtAge;
    @BindView(R.id.txt_join_time)
    TextView txtJoinTime;
    @BindView(R.id.txt_active_time)
    TextView txtActiveTime;
    @BindView(R.id.txt_census)
    TextView txtCensus;
    @BindView(R.id.txt_num)
    TextView txtNum;
    @BindView(R.id.txt_amount)
    TextView txtAmount;
    @BindView(R.id.txt_average)
    TextView txtAverage;
    @BindView(R.id.txt_status)
    TextView txtStatus;
    @BindView(R.id.txt_deduction_time)
    TextView txtDeductionTime;
    @BindView(R.id.txt_desc)
    TextView txtDesc;
    @BindView(R.id.txt_end)
    TextView txtEnd;
    @BindView(R.id.txt_pub)
    TextView txtPub;

    private PublicityDetailsAdapter adapter;
    private PublicityDetailsAdapter adapter1;
    private List<String> list;
    private List<String> list1;
    private String helpID;

    @Override
    protected void init() {
        ButterKnife.bind(this);
        initHead();
    }

    private void initHead() {
        headerview.setTitle("公示详情-轻松互助");
        headerview.bindOnclickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case HeaderView.LEFT:
                        finish();
                        break;
                }
            }
        });
    }

    @Override
    protected void responseData(PublicityDetailsProtocol mGsonBaseProtocal) {
        txtName.setText("互助会员: " + mGsonBaseProtocal.getData().getHelp_name());
        txtAge.setText("年龄: " + mGsonBaseProtocal.getData().getHelp_age() + "岁");
        txtJoinTime.setText("加入时间: " + DateUtils.stampToDateDay(mGsonBaseProtocal.getData().getJoin_time()));
        txtActiveTime.setText("生效时间: " + DateUtils.stampToDateDay(mGsonBaseProtocal.getData().getActive_time()));
        txtCensus.setText("户籍: " + mGsonBaseProtocal.getData().getHelp_census());
        txtNum.setText("参与人数: " + mGsonBaseProtocal.getData().getMembers_num() + "人");
        txtAmount.setText("互助金额: " + mGsonBaseProtocal.getData().getHelp_amount());
        txtAverage.setText("每位会员均摊: " + mGsonBaseProtocal.getData().getAverage_amount() + "元");
        txtStatus.setText("公式状态: " + (mGsonBaseProtocal.getData().getIs_audit().equals("0") ? "待审核" : "已救助"));
        txtDeductionTime.setText("扣款日期: " + DateUtils.stampToDateDay(mGsonBaseProtocal.getData().getDeduct_time()));
        txtDesc.setText(mGsonBaseProtocal.getData().getEvent_desc());
        txtEnd.setText(mGsonBaseProtocal.getData().getProcess_end());
        txtPub.setText(mGsonBaseProtocal.getData().getHelp_pub());

        list = StringImageToList.toList(mGsonBaseProtocal.getData().getRelated_data());
        list1 = StringImageToList.toList(mGsonBaseProtocal.getData().getProof_img());
        adapter = new PublicityDetailsAdapter(this, list);
        adapter1 = new PublicityDetailsAdapter(this, list1);
        gridview.setAdapter(adapter);
        gridview1.setAdapter(adapter1);
        gridview.setOnItemClickListener(new MyItemClick());
        gridview1.setOnItemClickListener(new MyItemClick1());
    }

    @Override
    protected HttpLoader initHttpLoader() {
        helpID = getIntent().getStringExtra("help_id");
        RequestHttpLoader requestHttpLoader = new RequestHttpLoader(PublicityDetailsProtocol.class);
        Map map = new HashMap();
        map.put("help_id", helpID);
        requestHttpLoader.setParams(NetConfig.HELP_INFO, map);
        return requestHttpLoader;
    }

    @Override
    protected boolean isRequestData() {
        return true;
    }

    @Override
    protected int initContentView() {
        return R.layout.publicity_details_activity;
    }

    @Override
    public boolean onEventBus(BaseEventBean baseEventBean) {

        return false;
    }

    class MyItemClick implements AdapterView.OnItemClickListener {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Preview.preview(PublicityDetailsActivity.this, list, position, gridview, getStatusBarHeight());
        }
    }

    class MyItemClick1 implements AdapterView.OnItemClickListener {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Preview.preview(PublicityDetailsActivity.this, list, position, gridview1, getStatusBarHeight());
        }
    }
}
